<?php
	function products_getchunk() {
		global $kiwee, $_lang;
		
		echo $kiwee->getChunkContent($_POST['chunkid']);

		

	}

	function products_properties() {
		global $kiwee, $_lang;
		
		// See if page exists (assuming edit and not create)
		if ($_POST['itemid'] != 0){
			$itemprops = $kiwee->getItemProperties($_POST['itemid']);
		} else { // Set $itemprops to default vals for new item
        	$itemprops['id'] = 0;
			$itemprops['itemid'] = $_POST['itemid']; // not used right now
			$itemprops['sku'] = '';
	        $itemprops['name'] = '';
	        $itemprops['fullname'] = '';
	        $itemprops['description'] = '';
	        $itemprops['amount'] = 0.00;
	        $itemprops['oversized'] = 0.00;
	        $itemprops['hazmat'] = 0.00;
	        $itemprops['disabled'] = $kiwee->config['newproduct_active_default'];
	        $itemprops['shoppingenabled'] = $kiwee->config['newproduct_shopping_default'];
	        $itemprops['quoteenabled'] = $kiwee->config['newproduct_quoting_default'];
	        $itemprops['status'] = 'EW';
			$itemprops['pagetemplate'] = $kiwee->config['pagetemplate_default'];
			$itemprops['contentarea'] = '{{Product Template 1}}';
		}

		echo '<div id="edititemproperties">';
		
		echo '<div id="edittopopspanel">';
		echo "\n" . '<table style="height: 100%";>' . "\n";
		echo "\t\t" . '<tr>' . "\n";
		echo "\n" . '<table>' . "\n";
		echo "\t" . '<tr>' . "\n";

		echo "\t\t" . '<td>' . "\n";
		echo '<label style="color: white; font-size: 12px;">SKU: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td>' . "\n";
		echo '<input tabindex="1" type="text" id="edititemsku" size=20 value="' . $itemprops['sku'] . '">';
		echo "\t\t" . '</td>' . "\n";

		echo "\t\t" . '<td>' . "\n";
		echo '<label style="color: white; font-size: 12px;">Name: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td>' . "\n";
		echo '<input tabindex="2" type="text" id="edititemname" size=20 value="' . $itemprops['name'] . '">';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td>' . "\n";
		echo '<label style="color: white; font-size: 12px;">Short Description: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td>' . "\n";
		echo '<input tabindex="3" type="text" id="editshortdescription" size=40 value="' . $itemprops['description'] . '">';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td style="display:none;">' . "\n";
		echo '<label style="color: white; font-size: 12px;">Audit Status: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td style="display:none;">' . "\n";
		echo '<select tabindex="20" style="color: black;" id="editstatus" DISABLED>';

		if ($itemprops['status']=='new'){
			$enbl = 'SELECTED';
		}else {
			$enbl = '';
		}
		echo '<option ' . $enbl. ' value="new">New</option>';

		if ($itemprops['status']=='current'){
			$enbl = 'SELECTED';
		}else {
			$enbl = '';
		}
		echo '<option ' . $enbl . ' value="current" READONLY>Current</option>';

		if ($itemprops['status']=='deleted'){
			$enbl = 'SELECTED';
		}else {
			$enbl = '';
		}
		echo '<option ' . $enbl . ' value="deleted">Deleted</option>';

		if ($itemprops['status']=='updated'){
			$enbl = 'SELECTED';
		}else {
			$enbl = '';
		}
		echo '<option ' . $enbl . ' value="updated">Updated</option>';

		echo '</select>';		
		echo "\t\t" . '</td>' . "\n";
		echo "\t" . '</tr>' . "\n";
		echo '</table>';
		echo "\t\t" . '</tr>' . "\n";
		echo "\t\t" . '<tr>' . "\n";
		echo '<table style="width:200px">';
		
		echo "\t" . '<tr>' . "\n";
		echo "\t\t" . '<td style="align:left">' . "\n";
		echo '<label style="color: white; font-size: 12px;">Price: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td style="align:left;">' . "\n";
		echo '<input tabindex="5" type="text" id="editprice" size=5 value="' . $itemprops['amount'] . '">';
		echo "\t\t" . '</td>' . "\n";

		echo "\t\t" . '<td style="padding-left: 10px; align:left">' . "\n";
		echo '<label style="color: white; font-size: 12px;">Oversized Fee: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td style="align:left">' . "\n";
		echo '<input tabindex="6" type="text" id="editoversized" size=5 value="' . $itemprops['oversized'] . '">';
		echo "\t\t" . '</td>' . "\n";

		echo "\t\t" . '<td style="padding-left: 10px; align:left">' . "\n";
		echo '<label style="color: white; font-size: 12px;">Hazmat Fee: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td style="align:left">' . "\n";
		echo '<input tabindex="7" type="text" id="edithazmat" size=5 value="' . $itemprops['hazmat'] . '">';		
		echo "\t\t" . '</td>' . "\n";
		echo "\t" . '</tr>' . "\n";
		echo '</table>';
		echo "\t\t" . '</tr>' . "\n";
		echo "\t\t" . '<tr>' . "\n";
		echo '<table>';
		echo "\t" . '<tr>' . "\n";
		echo "\t\t" . '<td colspan=8>' . "\n";
		echo '<label style="color: white; font-size: 12px;">Enable Shopping Basket: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td colspan=6>' . "\n";
		if ($itemprops['shoppingenabled']=='ENABLED'){
			$enbl = 'CHECKED';
		}else {
			$enbl = '';
		}
		echo '<input tabindex="8" ' . $enbl . ' id="editenableshop" type="checkbox">';		
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td colspan=2>' . "\n";
		echo '<label style="color: white; padding-left: 20px; font-size: 12px;">Enable Quote Basket: </label>';
		echo '<p style="padding-left:20px; color: #ff1567; size: 10px;" >Not Implemented Yet!</p>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td colspan=1>' . "\n";
		if ($itemprops['quoteenabled']=='ENABLED'){
			$enbl = 'CHECKED';
		}else {
			$enbl = '';
		}
		echo '<input tabindex="9" ' . $enbl . ' id="editenablequote" type="checkbox">';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td>' . "\n";
		echo '<label style="color: white; padding-left: 20px; font-size: 12px;">Active: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td>' . "\n";
		if ($itemprops['disabled']=='ENABLED'){
			$enbl = 'CHECKED';
		}else {
			$enbl = '';
		}
		echo '<input tabindex="10" ' . $enbl . ' id="editactive" type="checkbox">';
		echo "\t\t" . '</td>' . "\n";
		echo "\t" . '</tr>' . "\n";
		echo '</table>';
		echo "\t\t" . '</tr>' . "\n";
		echo "\t\t" . '<tr>' . "\n";
		echo '<table>';
		echo "\t" . '<tr>' . "\n";
		echo "\t\t" . '<td colspan=2>' . "\n";
		echo '<label style="color: white; font-size: 12px;">Page Template: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td colspan=2>' . "\n";
		$kiwee->getTemplates($itemprops['pagetemplate']);
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td colspan=2 style="padding-left: 10px; ">' . "\n";
		echo '<label style="color: white; font-size: 12px;">Content Area Template: </label>';
		echo "\t\t" . '</td>' . "\n";
		echo "\t\t" . '<td colspan=2>' . "\n";
		$kiwee->getChunks($kiwee->config['contenttemplate_category']);
		echo "\t\t" . '</td>' . "\n";
		echo "\t" . '</tr>' . "\n";
		echo "\n" . '</table>' . "\n";
		echo '</div>';
		echo "\t\t" . '</tr>' . "\n";
		echo "\t\t" . '<tr style="height: 100%;">' . "\n";
		echo '<input type="hidden" id="pageid" value="' . $_POST['itemid'] . '">';
		echo '<textarea id="contentArea" onclick="enableEdit("contentArea");" name="contentArea" style="width: 100%; height: 100%;">' . $itemprops['contentarea'] . '</textarea>';
		echo "\t\t" . '</tr>' . "\n";

		echo "\t\t" . '</tr>' . "\n";
		echo "\t\t" . '<tr>' . "\n";
		
		echo '<div id="buttonpanel">';
		echo '<button id="updatebutton" onclick="updateitemproperties(' . $_POST['itemid'] . ');">Update</button>';
		echo '<button id="closeeditbutton" onclick="hideBox();">Close</button>';
		echo '</div>';
		echo "\t\t" . '</tr>' . "\n";
		echo '</table>' . "\n";		
		echo '</div>';
	}

	function products_update() {
		global $kiwee, $_lang;
		echo $kiwee->updatePage($_POST['itemid'], $_POST['sku'], $_POST['itemname'], $_POST['shortdescription'], $_POST['contentarea'], $_POST['price'], $_POST['hazmat'], $_POST['oversized'], $_POST['status'], $_POST['active'], $_POST['enablequote'], $_POST['template'], $_POST['enableshop']);
	}

	function products_gridload() {
		global $kiwee, $_lang;
	    $sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit';
	    mysql_select_db($dbname);
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
	    $grd->altItemClass="gridAltItem";
	    $grd->fields="sku, status, name, description, disabled, amount";
        $grd->columns= $_lang["import_item_id"]. ", " . $_lang["import_status"] . "," . $_lang["import_name"] . ", " . $_lang["import_description"] . ", " . $_lang["import_isactive"] . ", " . $_lang["import_price"] . ", " . $_lang["import_edit_options"] . ", " . $_lang["import_addbutton"];
	    $grd->colWidths="34,50,34,200,34,50,50,50";
	    $grd->colAligns="left, left, left, left, center, left, center, center";
	    $grd->colTypes=",,,,,currency,template:<button id=\"edititemoptions\" onclick=\"edititemoptions([+items_id+])\">Edit Options</button> ,template:<button id=\"edititem\" onclick=\"edititemproperties([+id+]);\">Edit</button>";
		if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
	    echo $grd->render();	
	}

	function products_statsload() {
		global $kiwee, $_lang;
		
	    $itemstat = $kiwee->getItemStats();
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 46px;">New Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['newitems'] . '</p>';
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 28px;">Current Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['currentitems'] . '</p>';
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 28px;">Deleted Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['deleteditems'] . '</p>';
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 25px;">Updated Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['updateditems'] . ' </p>';
	    echo '<p style="font-weight:bold; font-size:16px; padding-left: 20px;">Total Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['totalitems'] . '</p>';
	    echo '</div>';
	}

	function products_search() {
		global $kiwee, $_lang;
		
		if ($_POST['sku']!=""){
		 	$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit where items_id=' . $_POST['sku'];
		} else {
			$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit';	
		}
	    mysql_select_db($dbname);
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
	    $grd->altItemClass="gridAltItem";
    	$grd->fields="sku, status, name, description, disabled, amount";
        $grd->columns= $_lang["import_item_id"]. ", " . $_lang["import_status"] . "," . $_lang["import_name"] . ", " . $_lang["import_description"] . ", " . $_lang["import_isactive"] . ", " . $_lang["import_price"] . ", " . $_lang["import_edit_options"] . ", " . $_lang["import_addbutton"];
	    $grd->colWidths="34,50,34,200,34,50,50,50";
	    $grd->colAligns="left, left, left, left, center, left, center, center";
	    $grd->colTypes=",,,,,currency,template:<button id=\"edititemoptions\" onclick=\"edititemoptions([+items_id+])\">Edit Options</button> ,template:<button id=\"edititem\" onclick=\"edititemproperties([+id+]);\">Edit</button>";
		if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
	    echo $grd->render();				
	}

	function products_updateoptions() {
		global $kiwee, $_lang;
		
		echo $kiwee->updateItemOptions($_POST['itemid'], $_POST['chosenoptionsdiv']);
	}

	function products_options() {
		global $kiwee, $_lang;
		
		// Quick explanation of what to do in this interface
		echo '<p style="color: white; font-size: 14px; padding-bottom: 10px;">Choose which options to associate with your item:</p>';
		
		// Titles for Interface
		echo '<div id="chosenoptionstitle" style="width: 42%; color: white; font-size: 14px; float: right; padding-bottom: 10px;">';
		echo 'Chosen Options:';
		echo '</div>';
		echo '<div id="alloptionstitle" style="width: 47%; color: white; font-size: 14px; float:right; padding-bottom: 10px;">';
		echo 'Available Options:';
		echo '</div>';
				
		// Div for grid to show chosen options
		echo '<div id="chosenoptionsdiv" class="chosenoptionsdiv" style="overflow:auto; border-style: solid; border-width: 1px; border-color: #ff9933;width: 170px; height: 320px; margin-right: 5%; background-color: #657DA3; float: right;">';
		echo '<p></p>';
		$kiwee->getAllChosenOptions($_POST['itemid']);
		echo '</div>';		
		
		// Div for a list of all available (unused options)
		echo '<div id="alloptionsdiv" class="alloptionsdiv" style="overflow: auto; border-style: solid; border-width: 1px; border-color: #ff9933; width: 170px; margin-right: 7%; height: 320px; background-color: #657DA3; float: right;">';
		
		// Get Options and place in divs
		$kiwee->getAllItemOptions($_POST['itemid']);
				
		echo '</div>';
		
		// Div for buttons to close lightbox
		echo '<div id="buttonpanel" >';
		echo '<button style="margin-top: 10px;" onclick="products_updateoptions(' . $_POST['itemid'] . ');">Update</button>';
		echo '<button style="margin-top: 10px;" onclick="hideBox();">Close</button>';
		echo '</div>';
	}

	function products_filter() {
		global $kiwee, $_lang;
		
		switch($_POST['filterby']){
			case 'ALLITEMS':
				$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit';
			break;
			
			case 'NEWITEMS':
				$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit where status="new"';
			break;
			
			case 'CURRITEMS':
				$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit where status="current"';
			break;
			
			case 'UPDATEDITEMS':
				$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit where status="updated"';
			break;
			
			case 'DELETEDITEMS':
				$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'items_audit where status="deleted"';
			break;
		}
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
		$grd->altItemClass="gridAltItem";
	    $grd->fields="sku, status, name, description, disabled, amount";
	    $grd->columns= $_lang["import_item_id"]. ", " . $_lang["import_status"] . "," . $_lang["import_name"] . ", " . $_lang["import_description"] . ", " . $_lang["import_isactive"] . ", " . $_lang["import_price"] . ", " . $_lang["import_edit_options"] . ", " . $_lang["import_addbutton"];
	    $grd->colWidths="34,50,34,200,34,50,50,50";
	    $grd->colAligns="left, left, left, left, center, left, center, center";
	    $grd->colTypes=",,,,,currency,template:<button onclick=\"products_options([+items_id+])\">Edit Options</button> ,template:<button id=\"edititem\" onclick=\"edititemproperties([+id+]);\">Edit</button>";

		if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
	    echo $grd->render();
	}
/*
	} else if ($_POST['trxntype']=='updateitemstats'){
	    $itemstat = $kiwee->getItemStats();
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 46px;">New Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['newitems'] . '</p>';
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 28px;">Current Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['currentitems'] . '</p>';
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 28px;">Deleted Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['deleteditems'] . '</p>';
	    echo '<p style="font-weight:bold; font-size:11px; padding-left: 25px;">Updated Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['updateditems'] . ' </p>';
	    echo '<p style="font-weight:bold; font-size:16px; padding-left: 20px;">Total Items:&nbsp;&nbsp;&nbsp;&nbsp;' . $itemstat['totalitems'] . '</p>';
	    echo '</div>';

	if ($_POST['trxntype']=='add'){
		$kiwee->createList($_POST['listname'],$_POST['listdesc']);
	} else if ($_POST['trxntype']=='delete'){
		$kiwee->deleteList($_POST['listid']);
	} else if ($_POST['trxntype']=='editoptions'){
		echo '<form name="addoptiontolist" method="POST" action="' . "javascript:get(document.getElementById('addoptiontolist'))\">" . "\n";
		echo '	<label>Name:</label><input id="addoptionname" name="addoptionname" type="text" length=20 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '	<label>Value:</label><input id="addoptionvalue" name="addoptionvalue" type="text" length=100 />&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '	<label>Price Offset:</label><input id="addoptionoffset" name="addoptionoffset" type="text" length=100 />&nbsp;&nbsp;' . "\n";
		echo ' 	<input type="button" name="addoption" onClick="' . "javascript: get(this.parentNode, 'addoption'); \"" .' value="Add Option"/>' . "\n";
		echo '  <br /><br />';
		echo '</form>';
				
		$sql = 'SELECT * FROM ' . $kiwee->config['fpx'] . 'lists_options WHERE lists_id="' . $_POST['listid'] . '"';
		
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd3 = new DataGrid('',$ds, $number_of_results);
	    $grd3->noRecordMsg = $_lang["no_records_found"];
	    $grd3->cssClass="grid";
	    $grd3->columnHeaderClass="gridHeader";
	    $grd3->itemClass="gridItem";
	    $grd3->altItemClass="gridAltItem";
	    $grd3->fields="name, value, priceoffset";
	    $grd3->columns= $_lang["import_name"] . ", " . $_lang["list_value"] . "," . $_lang["list_offset"] . "," . $_lang["list_edit"] . "," . $_lang['list_delete'];
	    $grd3->colWidths="100,100,75, 50, 50";
	    $grd3->colAligns="left,left,left,center,center";
	    $grd3->colTypes=",,currency,template:<button id=\"editlistoptionbutton\" onClick=\"editlistoption([+id+])\" >Edit Item</button>,template:<button id=\"deletelistoptionbutton\" onClick=\"deletelistoption([+id+])\">Delete</button>";
	    if($listmode=='1') $grd2->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd2->pageNumber = 1;
		echo $grd3->render();		
	} else if ($_POST['trxntype']=='showoptionsgrid'){
		echo '<form name="addoptiontolist" method="POST" action="javascript:get(document.getElementById("addoptiontolist"))">' . "\n";
		echo '	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>Name:</label><input id="specifyname" name="specifyname" type="text" length=20 />'.
		  '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '	&nbsp;&nbsp;&nbsp;<label>Render As:</label><select onchange="chooseoptions();" id="chooserender" name="chooserender">' . "\n";
		echo "  \t" . '<option value="DROP" >Drop Down</option><br />' . "\n";
		echo "  \t" . '<option value="TEXT" >Text Box</option><br />' . "\n";
		echo "  \t" . '<option value="TEXTAREA" >Text Area</option><br />' . "\n";
		echo "  \t" . '<option value="CHECK" >Check Boxes</option><br />' . "\n";
		echo "  \t" . '<option value="MULTI" >Multi Select</option><br />' . "\n";
		echo "  \t" . '<option value="RADIO" >Radio Buttons</option><br />' . "\n";
		echo '  </select>';
		$opts = $kiwee->getAllLists();
		echo ' &nbsp;&nbsp;&nbsp;<label id="chooselistnamelabel">List Name:</label><select id="chooselistname" name="chooselistname" onchange="setdefaultoptions();">' . "\n";
		for ($i=0; $i < sizeof($opts); $i++){
			echo "\t" . '<option value="' . $opts[$i]['id'] . '" />' . $opts[$i]['name'] . '</option><br />' . "\n";
		}							 

		echo '  </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '  <div id="optionalspacer"><br /></div>' . "\n";
		echo '  <div style="display:none;" id="optionalstuff"><br />' . "\n";
		echo '  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="specifysizelabel">Size:</label><input id="specifysize" name="specifysize"'.
		  'type="text" length=10 />&nbsp;&nbsp;&nbsp;' . "\n";
		echo '  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="specifylengthlabel">Columns:</label><input id="specifylength" name="specifylength"'.
		  'type="text" length=10 />&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n";
		echo '  </div>';
		echo '	<label>HTML Class:</label><input id="specifyhtmlclass" name="specifyhtmlclass" type="text" length=100 />&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '	<label id="specifydefaultlabel">Default Value:</label><select id="specifydefault" name="specifydefault" />&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '  <div id="defaultoptionsdiv" name="defaultoptionsdiv">' . "\n";
		echo getDefaultOptions($opts[0]['name'], 'name', $kiwee);
		echo '  </div>';
		echo '  </select><br /><br />';
		echo ' 	<input type="button" name="addoption" onClick="' . "javascript: get(this.parentNode, 'addoption');\"" . ' value="Add Option"/>' . "\n";
		echo '  <br /><br />';
		echo '</form>';
		
		$sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'options';		
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd2 = new DataGrid('',$ds, $number_of_results);
	    $grd2->noRecordMsg = $_lang["no_records_found"];
	    $grd2->cssClass="grid";
	    $grd2->columnHeaderClass="gridHeader";
	    $grd2->itemClass="gridItem";
	    $grd2->altItemClass="gridAltItem";
	    $grd2->fields="name, renderas, htmlclass, size, length, deflt";
	    $grd2->columns= $_lang["import_name"] . ", " . $_lang["option_maintenance_render"] .  "," .  $_lang["option_maintenance_htmlclass"] . "," . $_lang["option_maintenance_size"] . "," . $_lang["option_maintenance_length"] . "," . $_lang["option_maintenance_edit"] . "," . $_lang['list_delete'];
	    $grd2->colWidths="100, 75, 100, 75, 75, 75";
	    $grd2->colAligns="left,left,left,left,left,left,center,center";
	    $grd2->colTypes=",,,,,template:<button id=\"editlistoptionbutton\" onClick=\"editoption([+id+])\" >Edit</button>,template:<button id=\"deletelistoptionbutton\" onClick=\"deleteoption([+id+])\">Delete</button>";
	    if($listmode=='1') $grd2->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd2->pageNumber = 1;
		echo $grd2->render();		
  } else if ($_POST['trxntype']=='addlistoption'){
	  	//echo $_POST['listid'] . "||" . $_POST['addoptionname'] . "||" . $_POST['addoptionvalue'] . "||" . $_POST['addoptionoffset'];
		$kiwee->createListOption($_POST['listid'], $_POST['addoptionname'], $_POST['addoptionvalue'], $_POST['addoptionoffset']);
  } else if ($_POST['trxntype']=='listmaintenancegrid'){
		$sql = 'SELECT * FROM ' . $kiwee->config['fpx'] . 'lists';
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
	    $grd->altItemClass="gridAltItem";
	    $grd->fields="name, description";
	    $grd->columns= $_lang["import_name"] . ", " . $_lang["import_description"] . "," . $_lang["list_edit"] . "," . $_lang["list_options_edit"] . "," . $_lang['list_delete'];
	    $grd->colWidths="100,300, 50, 50";
	    $grd->colAligns="left,left,center,center,center";
	    $grd->colTypes=",,template:<button id=\"editlistproperties\" onClick=\"editlistproperties([+id+])\">Edit</button>," .
						"template:<form id=\"action-[+id+]\" action=\"index.php?a=407\" method=\"post\">" .
						"<input type=\"hidden\" id=\"listname\" name=\"listname\" value=\"[+name+]\" />" .
						"<input type=\"hidden\" id=\"listid\" name=\"listid\" value=[+id+] />" .
						"<button id=\"editlistitem\" onClick=\"\" id=\"editlistitem\" name=\"editlistitems\">Edit Items</button></form>," .
						"template:<button id=\"delete\" onClick=\"deletelist([+id+])\">Delete</button>";
	    if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;		
		echo $grd->render();
	} else if ($_POST['trxntype']=='showtaxgrid'){
		$sql = 'SELECT * FROM ' . $kiwee->config['fpx'] . 'taxes';
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
	    $grd->altItemClass="gridAltItem";
	    $grd->fields="postalcode, description, rate";
	    $grd->columns= $_lang["tax_postalcode"] . ", " . $_lang["tax_description"] . ", " . $_lang["tax_rate"] . "," . $_lang['tax_delete'];
	    $grd->colWidths="100, 100, 50, 50";
	    $grd->colAligns="left,left, left,center";
	    $grd->colTypes=",,,template:<button id=\"delete\" onClick=\"deletetaxrate([+id+])\">Delete</button>";
	    if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;		
		echo $grd->render();
	} else if ($_POST['trxntype']=='deletelistoption'){
		$kiwee->deleteListOption($_POST['listoptionid']);	
	} else if ($_POST['trxntype']=='editlistproperties'){
		$listproperties = $kiwee->getListProperties($_POST['listid']);
		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">Name:</label>' .
		  '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' .
		  '<input id="editlistname" name="editlistname" type="text" value="' . $listproperties['name'] .
		  '" length=20 /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' .
		  '<label style="color: white;">Description:</label>&nbsp;&nbsp;' .
		  '<input id="editlistdesc" name="editlistdesc" type="text" value="' . 
		  $listproperties['description'] . '" length=20 /><br /><br />' . "\n";
		echo '<input style="color: green" type="button" onclick="updatelistproperties(' .
		  $_POST['listid']. ')" name="MakeChanges" value="Make Changes" /></button>' .
		  '<input type="button" style="color: green" name="CancelChanges" onclick="hideBox()" value="Cancel"></button>' . "\n";
	} else if ($_POST['trxntype']=='updatelistproperties'){
		$kiwee->updateList($_POST['listid'], $_POST['editlistname'], $_POST['editlistdesc']);
	} else if ($_POST['trxntype']=='editlistoption'){
		$kiwee->updateListOption($_POST['optionid'], $_POST['editlistoptionname'], $_POST['editlistoptionvalue'], $_POST['editlistoptionoffset']);
	} else if ($_POST['trxntype']=='editlistoptionproperties'){
		$listoptionproperties = $kiwee->getListOptionProperties($_POST['listoptionid']);
		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">Name:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="editlistoptionname" name="editlistname" type="text" value="' . $listoptionproperties['name'] . '" length=20 /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">Value:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="editlistoptionvalue" name="editlistdesc" type="text" value="' . $listoptionproperties['value'] . '" length=20 /><br /><br />&nbsp;<label style="color: white;">Price Offset:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="editlistoptionoffset" name="editlistoffset" type="text" value="' . number_format($listoptionproperties['offset'], 2) . '" length=20 /><br /><br />' . "\n";
		echo '<input style="color: green;" type="button" name="updatelistoption" id="updatelistoption" onclick="updatelistoption(' . $_POST['listoptionid'] . ')" value="Update" />' . "\n";
		echo '<input style="color: green;" type="button" name="cancelupdate" id="cancelupdate" onclick="hideBox()" value="Cancel" />' . "\n";  
	} else if ($_POST['trxntype']=='addoption'){
		$kiwee->createOption($_POST['chooselistname'], $_POST['specifyname'], $_POST['chooserender'], $_POST['specifyhtmlclass'], $_POST['specifysize'], $_POST['specifylength'], $_POST['specifydefault']);	
	} else if ($_POST['trxntype']=='editoptionproperties'){
		//Get Options selected right now
		$opt = $kiwee->getOption($_POST['optionid']);
		
		echo '  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">Name:</label><input id="editspecifyname" name="editspecifyname" value="' . $opt['name'] . '" type="text" length=20 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n";
		echo '  &nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">Render As:</label><select onchange="editchooseoptions();editsetdefaultoptions();" id="editchooserender" name="editchooserender">' . "\n";
		echo "  \t" . '<option ' . optselected($opt['renderas'],'SELECT') . ' value="DROP" >Drop Down</option><br />' . "\n";
        echo "  \t" . '<option ' . optselected($opt['renderas'], 'TEXT') . ' value="TEXT" >Text Box</option><br />' . "\n";
        echo "  \t" . '<option ' . optselected($opt['renderas'], 'TEXTAREA') . ' value="TEXTAREA" >Text Area</option><br />' . "\n";
        echo "  \t" . '<option ' . optselected($opt['renderas'], 'CHECK') . ' value="CHECK" >Check Boxes</option><br />' . "\n";
        echo "  \t" . '<option ' . optselected($opt['renderas'], 'MULTI') . ' value="MULTI" >Multi Select</option><br />' . "\n";
        echo "  \t" . '<option ' . optselected($opt['renderas'], 'RADIO') . ' value="RADIO" >Radio Buttons</option><br />' . "\n";        
		echo '  </select><br /><br />';
        echo '  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="editchooselistnamelabel" style="color: white;">List Name:</label><select onchange="editsetdefaultoptions();" id="editchooselistname" name="editchooselistname" />' . "\n";
        
		$opts = $kiwee->getAllLists();
        
		for ($i=0; $i < sizeof($opts); $i++){
			if ($opts['id'][$i]==$opt['listid']){
				$sel = 'SELECTED';	
			}else {
				$sel = '';
			}
			echo "\t" . '<option ' . $sel . ' value="' . $opts[$i]['id'] . '" />' . $opts[$i]['name'] . '</option><br />' . "\n";
		}
		
		echo '  </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n";
		echo '  <div style="display:block;" id="editoptionalstuff">' . "\n";
		echo '  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;" id="editspecifysizelabel">Size:</label><input id="editspecifysize" name="editspecifysize" value="' . $opt['size'] . '" type="text" length=10 />&nbsp;&nbsp;&nbsp;' . "\n";
		echo '  <br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;" id="editspecifylengthlabel">Columns:</label><input id="editspecifylength" name="editspecifylength" value=' . $opt['length'] . ' type="text" length=10 />&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n";
		echo '  </div>';
		echo '  &nbsp;&nbsp;<label style="color: white;">HTML Class:</label><input id="editspecifyhtmlclass" name="editspecifyhtmlclass" type="text" value="' . $opt['htmlclass'] . '" length=100 />&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n";
		$opts = $kiwee->getAllLists();
		echo '  <label style="color: white;" id="editspecifydefaultlabel">Default Value:</label><select id="editspecifydefault" name="editspecifydefault" /><div id="defaultoptionsdiv">'. getDefaultOptions($opts[0]['name'], 'name', $kiwee) . '</div> </select>&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n";
		
		echo '<input style="color: green;" type="button" name="updateoption" id="updateoption" onclick="updateoption(' . $_POST['optionid'] . ')" value="Update" />' . "\n";
		echo '<input style="color: green;" type="button" name="cancelupdate" id="cancelupdate" onclick="hideBox()" value="Cancel" />' . "\n";
	} else if ($_POST['trxntype']=='deleteoption'){
		$kiwee->deleteOption($_POST['optionid']);	
	} else if ($_POST['trxntype']=='getdefaultoptions'){
		echo getDefaultOptions($_POST['listname'], $_POST['idtype'], $kiwee);	
	} else if ($_POST['trxntype']=='updateoption'){
		$kiwee->updateOption($_POST['optionid'], $_POST['chooselistname'], $_POST['specifyname'], $_POST['chooserender'], $_POST['specifyhtmlclass'], $_POST['specifysize'], $_POST['specifylength'], $_POST['specifydefault']);	
	} else if ($_POST['trxntype']=='edituserproperties'){
 		$custinfo = $kiwee->getCustInfo($_POST['custid']);
		echo '<input type="hidden" id="editid" value="' . $custinfo['id'] . '" >' . "\n";
		echo '<input type="hidden" id="editinternalkey" value="' . $custinfo['custid'] . '" />' . "\n";
		echo '<label style="color: white; font-size:24px; float:right; margin-right: 60px;">Customer #: ' . $custinfo['id'] . '</label><br /><br /> ' . "\n";
		echo '<label style="color: white; float:left;">Company:</label><input id="editcompanyname" type="text" value="' . $custinfo['companyname'] . '" size=20><br /><br />' . "\n";
		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">First:</label><input id="editfname" type="text" value="' . $custinfo['fname'] . '" size=20>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Last:</label><input id="editlname" type="text" value="' . $custinfo['lname'] . '" size=20><br /><br />' . "\n";
		echo '<label style="color: white;">Address1:</label><input id="editaddr1" type="text" value="' . $custinfo['addr1'] . '" size=20>&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Address2:</label><input id="editaddr2" type="text" value="' . $custinfo['addr2'] . '" size=20><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">City:</label><input id="editcity" type="text" value="' . $custinfo['city'] . '" size=15>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">State:</label><input id="editstate" type="text" value="' . $custinfo['state'] . '" size=15>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Zip:</label><input id="editzip" type="text" value="' . $custinfo['zip'] . '" size=12><br /><br />&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Phone 1:</label><input id="editphone_1" type="text" value="' . $custinfo['phone_1'] . '" size=12>&nbsp;&nbsp&nbsp;' . "\n";
		echo '<label style="color: white;">ext1:</label><input id="editext_1" type="text" value="' . $custinfo['ext_1'] . '" size=5>&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Phone 2:</label><input id="editphone_2" type="text" value="' . $custinfo['phone_2'] . '" size=12>&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">ext2:</label><input id="editext_2" type="text" value="' . $custinfo['ext_2'] . '" size=5><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">fax:</label><input id="editfax" type="text" value="' . $custinfo['fax'] . '" size=10><br /><br />' . "\n";
		echo '<div style="border:1px; border-style:solid; border-color: #ff9933; padding: 10px; float:right; width:300px; margin-right: 90px; margin-top: 10px;" >' . "\n";
		echo '<p style="color: white; font-weight:bold; font-size:12px;">Web User Account</p>' . "\n";
		echo '&nbsp;&nbsp;<label style="color: white;">username:</label><input style="background-color: #444444; color: white;" id="editusername" type="text" value="' . $custinfo['username'] . '" size=10 readonly><br /><br />&nbsp;&nbsp;' . "\n";
		echo '<div id="passvalidatediv" style="display:none"><p style="color: red;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Passwords don\'t match</p></div>' . "\n";
		echo '<label style="color: white;">password:</label><input id="editpassword" type="password" onchange="passvalidator()" value="NOTAVALIDPASSWORD" size=12>&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">confirm:</label><input id="editpasswordconfirm" type="password" onchange="passvalidator()" value="NOTAVALIDPASSWORD" size=12><br /><br /> ' . "\n";
		echo '<label style="color: white;">Login Count:</label><input id="editlogincount" type="text" value="' . $custinfo['logincount'] . '" size=5>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Failed Logins:</label><input id="editfailedlogincount" type="text" value="' . $custinfo['failedlogincount'] . '" size=5><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Blocked:</label><input id="editblocked" type="text" value="' . $custinfo['blocked'] . '" size=1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Blocked Until:</label><input id="editblockeduntil" type="text" value="' . $custinfo['blockeduntil'] . '" size=7><br /><br />' . "\n";
		echo '<label style="color: white; margin-left:10px;">Comments:</label><br /><textarea style="margin-left:40px;" id="editcommentsection" rows=5 cols=35>' . $custinfo['commentssection'] . '</textarea>' . "\n";
		echo '</div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
		echo '<div style="margin-top:90px;">';
		echo '<button id="updateform" style="hide" onclick="updateuser();">Update</button>';
		echo '<button id="closeform" onclick="hideBox();">Close</button>';
		echo '</div>';
		echo '</div>';
	} else if ($_POST['trxntype']=='updateuserproperties'){
		echo $kiwee->updateCustInfo($_POST['editid'],$_POST['editinternalkey'],$_POST['companyname'],$_POST['fname'],$_POST['lname'],$_POST['addr1'],$_POST['addr2'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['phone_1'],$_POST['phone_2'],$_POST['ext_1'],$_POST['ext_2'],$_POST['fax'],$_POST['username'],$_POST['pass'],$_POST['logincount'],$_POST['failedlogincount'],$_POST['blocked'],$_POST['blockeduntil'],$_POST['commentsection']);
	} else if ($_POST['trxntype']=='addtaxrate'){
		$qry = 'insert into ' . $kiwee->config['fpx'] . 'taxes (postalcode, description, rate) values ("' . $_POST['postalcode'] . '","' . $_POST['description'] . '",' . $_POST['rate'] . ')';
		mysql_query($qry);
	} else if ($_POST['trxntype']=='deletetaxrate'){
		$qry = 'delete from ' . $kiwee->config['fpx'] . 'taxes where id=' . $_POST['id'];
		mysql_query($qry);
	} else if ($_POST['trxntype']=='updatecustomergrid'){
		if ($_POST['custsearch']!= ""){
			$sql= 'SELECT * from ' . $kiwee->config['fpx'] . 'customers where id=' . $_POST['custsearch'];	
		}else {
			$sql= 'SELECT * from ' . $kiwee->config['fpx'] . 'customers';	
		}
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
	    $grd->altItemClass="gridAltItem";
	    $grd->fields="id, lname, fname, companyname, lastorder, orderct, totalsales";
	    $grd->columns= $_lang["cust_id"]. ", " . $_lang["cust_lname"] . "," . $_lang["cust_fname"] . ", " . $_lang["cust_company"] . ", " . $_lang["cust_lastorder"] . ", " . $_lang["cust_orderct"] . ", " . $_lang["cust_totalorders"] . ", " . $_lang["cust_edit"];
	    $grd->colWidths="34,75,75,200,75,34,34,50,50";
	    $grd->colAligns="left, left, left, left, center, center, left, center";
	    $grd->colTypes=",,,,,,currency,template:<button id=\"edititem\" onclick=\"edituser([+id+])\">Edit</button>";
	    if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
	    echo $grd->render();
	} else if ($_POST['trxntype']=='vieworderinfo'){
		$ordinfo = $kiwee->getOrderInfo($_POST['orderid']);
		echo '<label style="color: white; font-size:24px; width: 160px; float:right; margin-left: 25%; float:right;">Order #: ' . $ordinfo['id']. '</label><br /><br />'."\n";
		echo '<label style="color: white; font-size:24px; width: 200px; float:left; margin-right: 10%;">Customer #: ' . $ordinfo['cust_id'] . '</label>' . "\n";
		echo '<label style="color: white; font-size:24px; width: 130px ; margin-left: 25%; float:right; ">PO #: ' . $ordinfo['ponumber'] . '</label><br /><br /><br />';
		echo '<div class="shipto" style="border:solid 1px; border-color: white; width: 250px; float: right; margin-bottom: 20px; font-weight: bold; height: 220px;">' . "\n";
		echo '<div style="background:#8FC70C; height:20px; width:250px;">' . "\n";
		echo '<p style="color:black; font-size:14px; float: right; width: 250px;">Ship To:</p>' . "\n";
		echo '</div>' . "\n";
		echo '<div style="background:#FFFFFF; height: 200px; padding-top:10px;">' . "\n";
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['shipfname'] . ' ' . $ordinfo['shiplname'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['shipcompanyname'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['shipaddr1'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['shipaddr2'] . '</p>';
echo '<p style="color: black; font-size:12px; margin-left: 40px;">'.$ordinfo['shipcity'].', '.$ordinfo['shipstate'].'&nbsp;&nbsp;' .$ordinfo['shipzip'].'<br/><br/><br/><br/>';
		echo '<p style="color: black; font-size:12px; margin-left: 25px;">Phone:&nbsp;&nbsp;' . $ordinfo['shipphone'] . '&nbsp;&nbsp;&nbsp;ext: ' . $ordinfo['sipext'] . '</p>';
		echo '</div>';
		echo '</div>';
		
		echo '<div class="billto" style="border:solid 1px; border-color: white; width: 250px; float: left; margin-bottom: 20px; font-weight: bold; height: 220px;">';
		echo '<div style="background:#8FC70C; height: 20px; margin-left: 0px; width: 250px;">';
		echo '<p style="color: black; font-size:14px; padding-left: 5px; float: left; width: 250px;" >Bill To:</p>';
		echo '</div>';
		echo '<div style="background:#FFFFFF; height: 200px; padding-top:10px;">';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['fname'] . ' ' . $ordinfo['lname'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['companyname'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['addr1'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['addr2'] . '</p>';
		echo '<p style="color: black; font-size:12px; margin-left: 40px;">' . $ordinfo['city'] . ', ' . $ordinfo['state'] . '&nbsp;&nbsp;' . $ordinfo['zip'] . '</p><br />';
		echo '<p style="color: black; font-size:12px; margin-left: 25px;">Phone:&nbsp;&nbsp;' . $ordinfo['phone_1'] . '&nbsp;&nbsp;&nbsp;ext: ' . $ordinfo['ext_1'] . '</p>';
	echo '<p style="color: black; font-size:12px; margin-left: 30px;">Other:&nbsp;&nbsp;' . $ordinfo['phone_2'] . "&nbsp;&nbsp;&nbsp;ext: " . $ordinfo['ext_2'] . '</p>';		
		echo '<p style="color: black; font-size:12px; margin-left: 31px;">Email:&nbsp;&nbsp;' . $ordinfo['email'] . '</p>';
		echo '</div>';

		echo '</div>';
		echo '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';

		echo '<div style="width: 560px; height: 25px; background: #8FC70C;">';
		echo '<p style="font-weight: bold; width: 200px; color: white; float: right; padding-top: 5px;">Submitted: ' . $ordinfo['created'] . '</p>';
echo '<p style="font-weight: bold; color: white; width: 200px; padding-top: 5px; margin-right: 20px; float: right;">Payment Approval: ' . $ordinfo['paymentApproved'] . '</p>';
		echo '<p style="font-weight: bold; width: 120px; color: white; padding-left: 20px; padding-top:5px; float: left;">Status: ' . $ordinfo['status'] . '</p><br />';

		echo '</div>';
		echo '<div style="margin-top: 10px;">';
		
	    $sql = 'SELECT * from ' . $kiwee->config['fpx'] . 'order_detail where order_id=' . $_POST['orderid'];
	    
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd2 = new DataGrid('',$ds, $number_of_results);
	    $grd2->noRecordMsg = $_lang["no_records_found"];
	    $grd2->cssClass="grid";
	    $grd2->columnHeaderClass="gridHeader";
	    $grd2->itemClass="gridItem";
	    $grd2->altItemClass="gridAltItem";
	    $grd2->fields="item_id, description, quantity, price, optionsprice, totalprice";
   $grd2->columns= $_lang["order_edit_id"] . ", " . $_lang["order_edit_description"] . ", " . $_lang["order_edit_quantity"] . ", " . $_lang["order_edit_price"] . ", " .  $_lang["order_edit_optionsprice"] . ", " . $_lang["order_total"];
	    $grd2->colWidths="50,200,50,50,50,50";
	    $grd2->colAligns="left,left,center,left,left,left";
	    $grd2->colTypes=",,,currency,currency,currency";
	    if($listmode=='1') $grd2->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd2->pageNumber = 1;
	    echo $grd2->render();		
		echo '</div><br />';
		echo '<div style="width: 210px; float: right; ">';

		echo '<p style="color: white; font-size:12px; width: 35px; float:right; padding-left: 10px; margin-right: 35px; text-align:right;">' .
		  number_format($ordinfo['subtotal'],2) . '</p>';
 		echo '<p style="color: white; font-size:12px; margin-left: 20px; width: 65px; float: left;">Subtotal:&nbsp;&nbsp;&nbsp;&nbsp;$</p>';
		
		echo '<p style="color: white; font-size:12px; width: 35px; float:right; padding-left: 10px; margin-right: 35px; text-align:right;">' .
		  number_format($ordinfo['tax'],2) . '</p>';
		echo '<p style="color: white; font-size:12px; margin-left: 20px; width: 65px; float: left;">Tax:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$</p>';

		echo '<p style="color: white; font-size:12px; width: 35px; float:right; padding-left: 10px; margin-right: 35px; text-align:right;">' .
		  number_format($ordinfo['tothandling'],2) . '</p>';		
		echo '<p style="color: white; font-size:12px; margin-left: 20px; width: 65px; float: left;">Handling:&nbsp;&nbsp;&nbsp;$</p>';

		echo '<p style="color: white; font-size:12px; width: 35px; float:right; padding-left: 10px; margin-right: 35px; text-align:right;">' .
		  number_format($ordinfo['totshipping'],2) . '</p>';
		echo '<p style="color: white; font-size:12px; margin-left: 20px; width: 65px; float: left;">Shipping:&nbsp;&nbsp;&nbsp;&nbsp;$';

		echo '<p style="color: white; font-size:12px; width: 35px; float:right; padding-left: 10px; margin-right: 35px; text-align:right;">' .
		  number_format($ordinfo['total'],2) . '</p>';
		echo '<p style="color: white; font-size:12px; margin-left: 20px; width: 65px; float: left; ">Total:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' .
		  '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$</p>';

		echo '<br />';
		echo '</div>';
		echo '<div style="margin-top: 100px;">';
		echo '<button id="returntomain" onclick="hideBox();">Close</button>';
		echo '</div>';
	} if ($_POST['trxntype'] =='updateordersgrid'){
		switch($_POST['sortordersby']){
			case 'ALLORDERS':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id';
			break;
			
			case 'NEWORDERS':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="NEW"';
			break;
			
			case 'CANCELLEDORDERS':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="CANCELLED"';
			break;
			
			case 'SHIPPEDORDERS':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="SHIPPED"';
			break;
			
			case 'ERRORORDERS':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="ERROR"';
			break;
			
			case 'PROCESSORDERS':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="PROCESSING"';
			break;

		 	case 'BACKORDERED':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="BACKORDER"';
			break;
			
		 	case 'UPDATED':
				$sql = 'SELECT A.id, A.created, A.paymentApproved, A.status, A.total, A.orderitems, B.fname, B.lname from ' . $kiwee->config['fpx'] . 'order_header as A INNER JOIN ' . $kiwee->config['fpx'] . 'customers as B where A.cust_id=B.id and A.status="UPDATED"';
			break;
		}	    
	    
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
  	    $grd->altItemClass="gridAltItem";
   	    $grd->fields="id, created, fname, lname, paymentApproved, status, total, orderitems";
	    $grd->columns= $_lang["order_id"] . ", " . $_lang["order_created"] . ", " . $_lang["order_fname"] . ", " . $_lang["order_lname"] . ", " .  $_lang["order_paymentApproved"] . ", " . $_lang["order_status"] . ", " . $_lang["order_total"] . ", " . $_lang["order_orderitems"] . ", " . $_lang["order_edit"];
        $grd->colWidths="34,30,100,100,40,50,40,20,34";
        $grd->colAligns="left,center,left,left,left,left,left,center,center";
        $grd->colTypes=",,,,,,currency,,template:<button id=\"ordermoredetail\" onclick=\"ordermoredetail([+id+])\">View</button>";
        if($listmode=='1') $grd->pageSize=0;
        	if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
        		echo $grd->render();		
	}
*/
	$oktxns[] = 'products_getchunk';
	$oktxns[] = 'products_properties';
	$oktxns[] = 'products_update';
	$oktxns[] = 'products_gridload';
	$oktxns[] = 'products_statsload';
	$oktxns[] = 'products_search';
	$oktxns[] = 'products_updateoptions';
	$oktxns[] = 'products_options';
	$oktxns[] = 'products_filter';
?>
